<!--#include file="conn.asp"-->
<%
'===============================模块===================================
'主要用于房间所有信息清零
'根据清除要求CMD清理房间信息
%>
<%
clearCMD(request("CMD"))

%>
<%
'=============================函数块====================================
Function clearCMD(CMD)
 Select case CMD
case "ALL"
call clearAll
case "TABLE"
call delTable
case "ROOM"
call clsRoom
case "CHATROOM"
call clsChatroom
 End Select
End Function


'=============================过程块======================================
Sub clearAll
'所有房间信息清空
'过程：先根据主表chatroom，删除所有附表,而后清空主表信息
set rs=server.createobject("adodb.recordset")
sql="select * from chatroom"
rs.open sql,conn,1,3
rs.movefirst
'response.write rs("ID")
while not rs.eof
saysTable="roomSay"&rs("ID")
sql1="drop table "+saysTable  '如何判断表存在而进行删除是一个遗留问题
'response.write sql1
conn.execute(sql1)
'response.write "success"

msgTable="roomTalkersMsg"&rs("ID")
sql2="drop table "+msgTable
conn.execute(sql2)
rs.delete
rs.update
rs.movenext
wend
response.write "All rooms is free!"
End Sub

Sub clsRoom
'creator退出房间时，删除该房间的附表，清空房间所有记录，实现退房
'接收的参数为：指定房间id---roomid
Dim roomID
roomID=cint(request("roomid"))
'response.write roomID
set rs=server.createobject("adodb.recordset")
sql="select * from chatroom where ID="&roomID
'response.write sql
rs.open sql,conn,1,3
'如果房间存在
if not rs.eof then
saysTable="roomSay"&roomID
sql1="drop table "+saysTable  
conn.execute(sql1)

msgTable="roomTalkersMsg"&roomID
sql2="drop table "+msgTable
conn.execute(sql2)
rs.delete
rs.update
response.write("room "&roomID&" is free!")
end if
End Sub


Sub delTable
'删除某一个指定表
'指定表名通过tn传递
sql="drop table "+trim(request("tn"))
conn.execute(sql)
response.write request("tn")+" table is killed!"
End Sub

Sub clsChatroom
'清空主表所有记录
sql="delete * from chatroom"
conn.execute(sql)
response.write("chatroom table is cleared up!")
end Sub
%>